/*
 * ModuleOT.java
 *
 * $Id: ModuleOT.java,v 1.1 2008-03-18 12:58:45 mario Exp $
 */
package org.ceteca.explica.core.installer;

import java.util.ArrayList;

/**
 * ValueObject with the data of a Module item.
 * <br/>
 * Responsibilities:
 * <ul>
 *  <li>Store the module data.</li>
 * </ul>
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2008 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class ModuleOT {
	/**
	 * Name of the module. It's the label that will be showed in the main 
	 * screen of the Explica application.
	 */
	private String name;
	/**
	 * Name of the main class of the module.
	 */
	private String mainClass;
	/**
	 * Name of the starting method of the module.
	 */
	private String mainMethod;
	/**
	 * Code of the resource correspondent to the module's icon.
	 */
	private String icon;
	/**
	 * Category used for the logging of the module.
	 */
	private String logCategory;
	/**
	 * Path of the logging configuration file for the module.
	 */
	private String logConfigFile;
	/**
	 * Path of the result messages properties file for the module.
	 */
	private String msgPropFile;
	
	private ArrayList<EntityOT> lEntities;
	
	/**
	 * ModuleOT constructor. It initializes all the module values.
	 * @param name String, module name.
	 * @param mainClass String, module main class.
	 * @param mainMethod String, module main method.
	 * @param icon String, module icon.
	 * @param logCategory String, module log category.
	 * @param logConfigFile String, module log configuration filename.
	 * @param msgPropFile String, module message properties filename.
	 */
	public ModuleOT(String name, String mainClass, String mainMethod, String icon, 
			String logCategory, String logConfigFile, String msgPropFile) {
		this.setName(name);
		this.setMainClass(mainClass);
		this.setMainMethod(mainMethod);
		this.setIcon(icon);
		this.setLogCategory(logCategory);
		this.setLogConfigFile(logConfigFile);
		this.setMsgPropFile(msgPropFile);
	}
	
	/**
	 * Gets the log category used for loggin the processes for the module.
	 * @return String, log category of the module.
	 */
	public String getLogCategory() {
		return logCategory;
	}
	/**
	 * Sets up the log category used for loggin the processes for the module.
	 * @param logCategory String, log category of the module.
	 */
	public void setLogCategory(String logCategory) {
		this.logCategory = logCategory;
	}

	/**
	 * Gets the path of the log configuration path for the module.
	 * @return String, path of the log configuration file of the module.
	 */
	public String getLogConfigFile() {
		return logConfigFile;
	}
	/**
	 * Sets up the path of the log configuration path for the module.
	 * @param logConfigFile String, path of the log configuration file of the module.
	 */
	public void setLogConfigFile(String logConfigFile) {
		this.logConfigFile = logConfigFile;
	}

	/**
	 * Gets the messages properties file name of the module.
	 * @return String, messages properties file name.
	 */
	public String getMsgPropFile() {
		return msgPropFile;
	}

	/**
	 * Sets up the messages properties file name of the module.
	 * @param msgPropertiesFile String, messages properties file name.
	 */
	public void setMsgPropFile(String msgPropertiesFile) {
		this.msgPropFile = msgPropertiesFile;
	}
	
	/**
	 * Gets the module's main classname, that is, the class that implements the
	 * method that starts the execution of the module.
	 * @return String, the main classname of the module.
	 */
	public String getMainClass() {
		return mainClass;
	}

	/**
	 * Sets up the module's main classname, that is, the class that implements the
	 * method that starts the execution of the module.
	 * @param moduleMainClass String, the main classname of the module.
	 */
	public void setMainClass(String moduleMainClass) {
		this.mainClass = moduleMainClass;
	}
	/**
	 * Gets the module's main method, that is, the name of the method that starts
	 * the execution of the module.
	 * @return String, the main method's name of the module.
	 */
	public String getMainMethod() {
		return mainMethod;
	}
	/**
	 * Sets up the module's main method, that is, the name of the method that starts
	 * the execution of the module.
	 * @param moduleMainMethod String, the main method's name of the module.
	 */
	public void setMainMethod(String moduleMainMethod) {
		this.mainMethod = moduleMainMethod;
	}
	
	/**
	 * Gets the code of the icon resource for the module.
	 * @return String, the icon of the module.
	 */
	public String getIcon() {
		return icon;
	}
	/**
	 * Sets up the code of the icon resource for the module.
	 * @param moduleIcon String, the icon of the module.
	 */
	public void setIcon(String moduleIcon) {
		this.icon = moduleIcon;
	}

	/**
	 * Gets the name of the module.
	 * @return String, the name of the module.
	 */
	public String getName() {
		return name;
	}
	/**
	 * Sets up the name of the module.
	 * @param moduleName String, the name of the module.
	 */
	public void setName(String moduleName) {
		this.name = moduleName;
	}
	
	/**
	 * Gets the module entities' list.
	 * @return ArrayList<EntityOT>, module list of entities.
	 */
	public ArrayList<EntityOT> getLEntities() {
		return lEntities;
	}
	/**
	 * Sets up the module entities' list.
	 * @param lEntities ArrayList<EntityOT>, module list of entities.
	 */
	public void setLEntities(ArrayList<EntityOT> entities) {
		lEntities = entities;
	}
	/**
	 * Adds a new entity to the module entities' list.
	 * @param entity EntityOT, data of the module entity.
	 */
	public void addEntity(EntityOT entity) {
		if (lEntities == null)
			lEntities = new ArrayList<EntityOT>();
		
		lEntities.add(entity);
	}
	
	/**
	 * Implementation of the toString method to format
	 * the data of the module.
	 * @return String, formatted module data for printing them out.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		
		result.append("---------------- MODULE ----------------\n");
		result.append("NAME: ");
		result.append(this.name);
		result.append("ICON: ");
		result.append(this.icon);
		result.append("\nMAIN CLASS: ");
		result.append(this.mainClass);
		result.append("\nMAIN METHOD: ");
		result.append(this.mainMethod);
		result.append("\nLOG CATEGORY: ");
		result.append(this.logCategory);
		result.append("\nLOG CONFIG FILE: ");
		result.append(this.logConfigFile);
		result.append("\nMSG FILE: ");
		result.append(this.msgPropFile);

		result.append("----------------------------------------\n");
		
		return result.toString();
	}
	
	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: ModuleOT.java,v 1.1 2008-03-18 12:58:45 mario Exp $";
	}
}
